# Contributor: Leo <thinkabit.ukim@gmail.com>
# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Maintainer: Francesco Colista <fcolista@alpinelinux.org>
pkgname=meson
pkgver=0.63.0
pkgrel=0
pkgdesc="Fast and user friendly build system"
url="https://mesonbuild.com"
arch="noarch"
license="Apache-2.0"
depends="samurai python3"
makedepends="py3-setuptools"
# glib-dev, gobject-introspection-dev, gtk+3.0-dev is a circular dep,
# but only during bootstrap-
# not installing checkdepends with !check should be fine
options="$options !check" # circular deps above with check on bootstrap
checkdepends="
	boost-dev
	boost-static
	cmake
	cups-dev
	doxygen
	gettext-static
	gfortran
	glib-dev
	gobject-introspection-dev
	gtest-dev
	gtk+3.0-dev
	libpcap-dev
	libxml2-dev
	linux-headers
	llvm-dev
	nasm
	ncurses-dev
	py3-pytest
	python3-dev
	vala
	zlib-dev
	zlib-static
	"
subpackages="
	$pkgname-doc
	$pkgname-vim::noarch
	$pkgname-bash-completion
	$pkgname-zsh-completion
	"
source="https://github.com/mesonbuild/meson/releases/download/$pkgver/meson-$pkgver.tar.gz
	skip-broken-tests.patch
	fix-ninja-output-test.patch
	abuild-meson
	"

prepare() {
	default_prepare

	# https://github.com/mesonbuild/meson/issues/10104
	rm -r "$builddir/test cases/linuxlike/13 cmake dependency"
}

build() {
	python3 setup.py build
}

check() {
	MESON_CI_JOBNAME=thirdparty \
		NINJA=samu \
		NINJA_1_9_OR_NEWER=1 \
		python3 run_tests.py
}

package() {
	python3 setup.py install --prefix=/usr --root="$pkgdir"

	install -Dm644 data/shell-completions/zsh/* -t "$pkgdir"/usr/share/zsh/site-functions
	install -Dm644 data/shell-completions/bash/* -t "$pkgdir"/usr/share/bash-completion/completions

	install -Dm0755 "$srcdir"/abuild-meson -t "$pkgdir"/usr/bin
}

vim() {
	pkgdesc="$pkgdesc (vim support)"
	install_if="vim $pkgname=$pkgver-r$pkgrel"
	cd "$builddir"
	for kind in ftdetect ftplugin indent syntax
	do
		mkdir -p "$subpkgdir"/usr/share/vim/vimfiles/$kind
		install -Dm644 \
			"$builddir"/data/syntax-highlighting/vim/$kind/meson.vim \
			"$subpkgdir"/usr/share/vim/vimfiles/$kind/meson.vim
	done
}

sha512sums="
8d427261bb42d2bd1da7d4f7b5f53908044aa2cea6d020fb320b0ab9d9848e17cf28deb12ae6dc139807f9e377db0c8a546561e94301216b634bd77703f17cea  meson-0.63.0.tar.gz
0bbbf65f56f4feab43b4ec3fbe7d4c64ef9abb563ea114d0b960048319b936dd577e538a762991661a1cb256f32c0da0fef2d3add07730e37a8bbd4ec27dc611  skip-broken-tests.patch
a60dd85ecc1004523c213f4d06bfe10ba906a5115e93cfa4f1b70733e0c16f39c2c22b38ff71bb07c67166f3121c263a56842e8f8e2022f0a44094f956e28f02  fix-ninja-output-test.patch
1029e7a7af86ff4a5636f8cea4b5dbe970a58741d2f25dad50712664f1e387078e7583fafd4f7d1d420c9e116b0ea72b20cf22532cfece9a7d2d8cf60c9aadab  abuild-meson
"
